<template>
  <!-- 新增群组或编辑群组 -->
  <el-dialog
    :title="editing ? '重命名' : '新增群组'"
    :visible.sync="show"
    width="30%"
  >
    <el-form :model="form_dialog">
      <el-input
        v-model="form_dialog.name"
        autocomplete="off"
        placeholder="群组名称"
      ></el-input>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="show = false">取 消</el-button>
      <el-button type="primary" @click="addEdit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["dialogVisible", "form", "editing"],
  computed: {
    // show代替dialogVisible，因为不能在子组件直接修改dialogVisible，form同理
    show: {
      get() {
        return this.dialogVisible;
      },
      set(bool) {
        this.$emit("update:dialogVisible", bool);
      },
    },
    form_dialog() {
      return this.form;
    },
  },
  methods: {
    // 修改父组件的dialogVisible，form，以及触发事件
    addEdit() {
      this.$emit("update:dialogVisible", false);
      this.$emit("update:form", this.form_dialog);
      this.$emit("addEdit");
    },
  },
};
</script>

<style>
</style>